import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:wallet_utils/base_router_config.dart';
import 'package:wallet_utils/button_style.dart';
import 'package:wallet_utils/color.dart';
import 'package:wallet_utils/ht_appbar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wallet_utils/text_style.dart';
import 'logic.dart';

class LoginPage extends StatelessWidget {
  final logic = Get.put(LoginPageLogic());
  final state = Get
      .find<LoginPageLogic>()
      .state;

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(
        BoxConstraints(
            maxWidth: MediaQuery.of(context).size.width,
            maxHeight: MediaQuery.of(context).size.height),
        context: context,
        designSize: const Size(375, 812),
        orientation: Orientation.portrait);
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.dark,
      child: Material(
        child: Container(
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: AssetImage("assets/bg_login.png"),
                fit: BoxFit.cover,
              ),
            ),
            child: Scaffold(
              backgroundColor: Colors.transparent,
              bottomNavigationBar: Container(
                height: 80.w + ScreenUtil().bottomBarHeight,
                alignment: Alignment.center,
                margin: EdgeInsets.only(left: 60.w, right: 60.w, bottom: ScreenUtil().bottomBarHeight + 57.w),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    InkWell(
                      onTap: () {
                        Get.toNamed(BaseRouterConfig.smsPage);
                      },
                      child: Column(
                        children: [
                          Image.asset('images/ic_phone.png', width: 46.w, height: 46.w,),
                          SizedBox(height: 10.w,),
                          Text('其他号码登录', style: TextStyleUtils.style999999(fontSize: 12.sp),)
                        ],
                      ),
                    ),
                    InkWell(
                      onTap: () {
                        Get.toNamed(BaseRouterConfig.pwdPage);
                      },
                      child: Column(
                        children: [
                          Image.asset('images/ic_lock.png', width: 46.w, height: 46.w,),
                          SizedBox(height: 10.w,),
                          Text('账号密码登录', style: TextStyleUtils.style999999(fontSize: 12.sp),)
                        ],
                      ),
                    ),
                  ],
                ),
              ),
              body: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    margin: EdgeInsets.only(
                      top: ScreenUtil().statusBarHeight + 12.h,
                      left: 15.w,
                    ),
                    child: backWidgetAction(backAction: () {
                      Get.back();
                    }),
                  ),
                  SizedBox(
                    height: 56.h,
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 30.w),
                    child: Text(
                      '你好,\n欢迎登录-放鑫钱包',
                      style: TextStyleUtils.style000000(fontSize: 27.w, fontWeight: FontWeight.bold),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 30.w, top: 50.w, bottom: 10.w),
                    child: Text(
                      '本机号码',
                      style: TextStyleUtils.style000000(fontSize: 16.w),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 30.w),
                    child: Text(
                      '188888888888',
                      style: TextStyleUtils.styleC1C1C1(fontSize: 18.sp),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 12.w, left: 30.w, right: 30.w),
                    width: double.infinity,
                    height: 0.5.w,
                    color: ColorManager.colorE7E8E9,
                  ),
                  GetBuilder<LoginPageLogic>(builder: (logic) {
                    return Container(
                      margin: EdgeInsets.only(left: 30.w, top: 24.w),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(right: 5.w),
                            child: GestureDetector(
                              behavior: HitTestBehavior.opaque,
                              onTap: () {
                                logic.updateUserPrivary();
                              },
                              child: Container(
                                width: 16.w,
                                height: 16.w,
                                margin: const EdgeInsets.only(top: 4),
                                alignment: Alignment.center,
                                child: state.isAgreeUserPrivary
                                    ? Image.asset(
                                  "images/ic_agreement_checked.png",
                                  width: 11.w,
                                  height: 11.w,
                                )
                                    : Image.asset(
                                  "images/ic_agreement_unchecked.png",
                                  width: 11.w,
                                  height: 11.w,
                                ),
                              ),
                            ),
                          ),
                          Expanded(
                            child: Text.rich(
                              TextSpan(
                                children: <InlineSpan>[
                                  TextSpan(text: "我已阅读并同意",
                                      style: TextStyleUtils.style999999(fontSize: 11.sp),
                                      recognizer: TapGestureRecognizer()
                                        ..onTap = () {}),
                                  TextSpan(
                                    text: "《使用条款》",
                                    style: TextStyle(color: ColorManager.color437EFF, fontSize: 11.sp, height: 1.5.w),
                                    // 设置点击事件
                                    recognizer: TapGestureRecognizer()
                                      ..onTap = () {},
                                  ),
                                  const TextSpan(
                                    text: "及",
                                  ),
                                  TextSpan(
                                    text: "《隐私协议》",
                                    style: TextStyle(color: ColorManager.color437EFF, fontSize: 11.sp, height: 1.5.w),
                                    // 设置点击事件
                                    recognizer: TapGestureRecognizer()
                                      ..onTap = () {},
                                  ),
                                ],
                              ),
                              style: TextStyle(
                                color: ColorManager.color999999,
                                fontSize: 13.sp,
                                height: 1.5,
                              ),
                              maxLines: 2,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ],
                      ),
                    );
                  }),
                  loginBtn(),
                ],
              ),
            )

        ),
      ),
    );
  }
}

//登录按钮
Widget loginBtn() {
  return Container(
    margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 50.w),
    width: double.infinity,
    height: 44.w,
    child: ElevatedButton(
        style: ButtonStyleUtils.buttonStyleF65247(),
        onPressed: () {

        },
        child: Text("本机号码一键登录", style: TextStyleUtils.styleFFFFFF(fontSize: 14))),
  );
}
